package com.duobaoyu.dby.supply.biz.client.product.bean.bo;

import com.duobaoyu.dby.common.core.constant.StringPool;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PlatformPriceCheckBO {


	private List<ErrorSkuInfo> errorSkuCodeList;

	@Data
	@Builder
	@NoArgsConstructor
	@AllArgsConstructor
	public static class ErrorSkuInfo{
		/**
		 * 错误skuCode
		 */
		private String errorSkuCode;
		/**
		 * 错误code
		 */
		private Integer errorCode;
		/**
		 * 错误说明
		 */
		private String errorMessage;
	}

	/**
	 * 是否存在错误的sku
	 */
	public boolean existsErrorSku() {
		return CollectionUtils.isNotEmpty(errorSkuCodeList);
	}

	/**
	 * 获取错误信息描述
	 * @param maxLength 返回的最大长度
	 */
	public String errorMessage(Integer maxLength) {
		if (CollectionUtils.isEmpty(errorSkuCodeList)) {
			return StringPool.EMPTY;
		}
		StringBuilder stringBuilder = new StringBuilder();
		for (ErrorSkuInfo errorSkuInfo : errorSkuCodeList) {
			stringBuilder.append(String.format("SKU编码%s:%s", errorSkuInfo.getErrorSkuCode(), errorSkuInfo.getErrorMessage())).append(StringPool.SEMICOLON);
		}
		int length = stringBuilder.length();
		if(maxLength!=null && length > maxLength) {
			stringBuilder.setLength(maxLength);
		}
		return stringBuilder.toString();
	}

}
